using TMPro;
using UnityEngine;
using UnityEngine.UI;

namespace CardGameObject.UnpackScene
{
    public class UnpackPackage: MonoBehaviour
    {
        public int Id { get; set; }
        public int CardCount { get; set; }
        public int PackageCount { get; set; }
        
        public Image PackageImage;
        public TextMeshProUGUI PackageCountText;

        private UnpackManager unpackManager;
        
        private void Start()
        {
            unpackManager = UnpackManager.GetInstance();
        }
        
        public void SetPackageInfo(int packageId, string packageName , int cardCount , int packageCount)
        {
            Id = packageId;
            CardCount = cardCount;
            PackageCount = packageCount;

            PackageCountText.text = PackageCount.ToString();
            
            Sprite sprite = Resources.Load<Sprite>($"Images/PackageImage/Content/{packageName}");
            if (sprite != null)
            {
                PackageImage.sprite = sprite;
            }
        }
        
        public void OnClick()
        {
            unpackManager.UnpackPackage(Id , CardCount);
            PackageCount -= 1;
            if (PackageCount == 0)
            {
                Destroy(gameObject);
                return;
            }
            PackageCountText.text = PackageCount.ToString();
            
        }
    }
}